﻿using System.Collections;
using System.IO;
using LitJson;
using System.Text;
using System.Collections.Generic;

public static class LStatic {
    //公共---------------------------------------------------------------------------------------------------------------------------
    public static JsonData cover_battleConfig { get; private set; }

    public static JsonData cover_config { get; private set; }
    public static JsonData cover_stage { get; private set; }
    public static JsonData cover_item { get; private set; }
    public static JsonData cover_monster { get; private set; }
    public static JsonData cover_shop { get; private set; }
    public static JsonData cover_attPoint { get; private set; }

    public static JsonData cover_skill { get; private set; }

    static string m_path;
    public static string[] m_nickName;
    public static void Init(string path)
    {
        m_path = path;


        cover_battleConfig = ParseJson("battleConfig.json");

        cover_config = ParseJson("config.json");
        cover_stage = ParseJson("stage.json");
        cover_item = ParseJson("item.json");
        cover_monster = ParseJson("monster.json");

        cover_skill = ParseJson("skill.json");
        //List<string> deleteKeys = new List<string>();//删除未开通的技能
        //foreach (string key in cover_skill.Keys)
        //{
        //    if((int)cover_skill[key]["opend"]==0)
        //        deleteKeys.Add(key);
        //}
        //deleteKeys.ForEach(n =>
        //{
        //    ((IDictionary)cover_skill).Remove(n);
        //});

        cover_shop = ParseJson("shop.json");
        cover_attPoint= ParseJson("attPoint.json");


        m_nickName = File.ReadAllLines(m_path+"/nickName.txt", Encoding.UTF8);
    }
    public static JsonData ParseJson(string str)
    {
        str = m_path + str;
        StreamReader sr = new StreamReader(str);
        return JsonMapper.ToObject(sr.ReadToEnd());
    }

    public static JsonData ParseMap(string str)
    {
        str = str+".json";
        StreamReader sr = new StreamReader(str);
        return JsonMapper.ToObject(sr.ReadToEnd());
    }

    public static string HomeName()
    {
        return cover_config["homeMapName"].ToString();
    }
    //公共---------------------------------------------------------------------------------------------------------------------------
  



    //server---------------------------------------------------------------------------------------------------------------------------

    public static JsonData GetStageByID(string id)
    {
        foreach (JsonData data in cover_stage)
        {
            if (id == data["stage_id"].ToString())
                return data;
        }
        return "";
    }
    //server---------------------------------------------------------------------------------------------------------------------------

    


    //client---------------------------------------------------------------------------------------------------------------------------


   
    //client---------------------------------------------------------------------------------------------------------------------------
}
